function sendMsg(aForm) {
    chrome.extension.sendRequest({cmd: "sendmsg",data:aForm}, function(response) {
	    
	});
	$('#msgArea').contents().find("body").html('');
}
function getqmsg(){
    chrome.extension.sendRequest({cmd: "getqmsg",data: "0"}, function(response) {
	    var msgText=response.result.data;
		if(msgText!=""){
		    $('#iResp').append(msgText);
			document.getElementById('iResp').lastChild.scrollIntoView();
		}
		setTimeout("getqmsg()",500);
	});
}
$(function(){
	$('#sendForm').submit(function(){
	    var aForm = new Object();
		aForm.sendTo=new Object();
		aForm.msg=new Object();
	    aForm.msg.value=$('#msgArea').contents().find("body").html();
		
		sendMsg(aForm);
		return false;
	});
	chrome.extension.sendRequest({cmd: "getcontext",data:"0"}, function(response) {
	    $('#iResp').html(response.result.data);
		if(document.getElementById('iResp').lastChild){
		    document.getElementById('iResp').lastChild.scrollIntoView();
		}
		setTimeout("getqmsg()",500);
	});
});

$(window).unload(function(){
    var context=$('#iResp').html();
    chrome.extension.sendRequest({cmd: "storecontext",data:context}, function(response) {
	    
	});
});